package controller

import (
	"context"
	"eag_arch_layout/internal/conf"
	"eag_arch_layout/internal/svc"

	pb "eag_arch_layout/api/baseArch/v1"
)

type SystemController struct {
	pb.UnimplementedSysServer
	baseCtrl
	jwtConfig *conf.Jwt
	ss        *svc.SystemSvc
}

func NewSystemController(jwtConf *conf.Jwt, ss *svc.SystemSvc) *SystemController {
	return &SystemController{ss: ss, jwtConfig: jwtConf}
}

func (s *SystemController) Login(_ context.Context, req *pb.LoginRequest) (*pb.LoginReply, error) {
	return s.ss.Login(s.jwtConfig, req)

}
func (s *SystemController) ChangePassword(ctx context.Context, req *pb.ChgPwdRequest) (*pb.ChgPwdReply, error) {
	if ok, msg1 := s.GetCurUser(ctx); ok {
		flag, msg, e2 := s.ss.ChangePassword(s.user.LoginId, req)
		return &pb.ChgPwdReply{Success: flag, Error: msg}, e2
	} else {
		return &pb.ChgPwdReply{Success: false, Error: msg1}, nil
	}
	//d := ctx.Value(model.CUR_USER_KEY)
	//if curUser, ok := d.(VO.CurUserInfo); ok {
	//	flag, msg, e2 := s.ss.ChangePassword(curUser.LoginId, req)
	//	return &pb.ChgPwdReply{Success: flag, Error: msg}, e2
	//}
	//return &pb.ChgPwdReply{Success: false, Error: "用户信息获取失败,请重新登录!"}, nil
}
func (s *SystemController) Logout(ctx context.Context, req *pb.LogoutRequest) (*pb.LogoutReply, error) {
	return &pb.LogoutReply{}, nil
}
func (s *SystemController) GetVersion(ctx context.Context, req *pb.GetVersionRequest) (*pb.GetVersionReply, error) {
	return s.ss.GetLastVersion()
	//return &pb.GetVersionReply{}, nil
}
